﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Everynet;
using System.ComponentModel.DataAnnotations;
using System.Web.Mvc;
using System.Linq.Expressions;
using System.Web.Mvc.Html;
using System.ComponentModel;

namespace Everynet.Models
{
    public class AgreementModel
    {
        public Int64 ID { get; set; }
        public string Agreement { get; set; }

        [Required]
        [Display(Name = "I agree to all of the above.")]
        [BooleanRequired(ErrorMessage = "You must accept the Agreement.")]
        public bool Agreementcheck { get; set; }
        public IEnumerable<DynamicAgreementModel> listDynamicAgreement { get; set; }

        public IEnumerable<DynamicAgreementModel> listDynamicAgreementHardware { get; set; }
    }

    //Custom Validation
    public class BooleanRequiredAttribute : ValidationAttribute, IClientValidatable
{
    public override bool IsValid(object value)
    {
        if (value is bool)
            return (bool)value;
        else
            return true;
    }

    public IEnumerable<ModelClientValidationRule> GetClientValidationRules(
        ModelMetadata metadata,
        ControllerContext context)
    {
        yield return new ModelClientValidationRule
                            {
                                ErrorMessage = FormatErrorMessage(metadata.GetDisplayName()),
                                ValidationType = "booleanrequired"
                            };
    }
}
}